/**************************************************************************************
* Component of simpleRTJ regression tests.
**************************************************************************************
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL RTJ COMPUTING BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Created by:
*       RTJ Computing
**************************************************************************************/

import lpc2xxx.hw.*;

public class TestClone
{
    class AClass implements Cloneable
    {
        private StringBuffer str = new StringBuffer();

        AClass(String str)
        {
            this.str.append(str);
        }
        void append(String str)
        {
            this.str.append(str);
        }
        String getStr()
        {
            return str.toString();
        }
        public Object clone() throws CloneNotSupportedException
        {
            return super.clone();
        }
    }

    class BClass
    {
        public Object clone() throws CloneNotSupportedException
        {
            return super.clone();
        }
    }

    public void test() throws Exception
    {
        BClass bc = new BClass();
        boolean ok = false;
        try
        {
            bc.clone();
        }
        catch (CloneNotSupportedException e)
        {
            ok = true;
        }
        if (!ok)
            throw new Exception("CL1");

        AClass c = new AClass("Test");
        AClass cc = null;
        try
        {
            cc = (AClass)c.clone();
            if (cc == null)
                throw new Exception("CL2");
        }
        catch (CloneNotSupportedException e)
        {
            throw new Exception("CL3");
        }
        if (!c.getStr().equals("Test") || !cc.getStr().equals("Test"))
            throw new Exception("CL4");
        c.append("1");
        if (!c.getStr().equals("Test1") || !cc.getStr().equals("Test1"))
            throw new Exception("CL4");
        cc.append("1");
        if (!c.getStr().equals("Test11") || !cc.getStr().equals("Test11"))
            throw new Exception("CL5");

        byte[] b = new byte[10];
        for (byte i=0; i < 10; i++)
            b[i] = (byte)(50+i);

        byte[] bb = null;
        try
        {
            bb = (byte[])b.clone();
            if (bb == null)
                throw new Exception("CL6");
        }
        catch (CloneNotSupportedException e)
        {
            throw new Exception("CL7");
        }
        ok = true;
        for (byte i=0; i < 10; i++)
            if (b[i] != (byte)(50+i) || bb[i] != (byte)(50+i))
                throw new Exception("CL8");

        Object[] o = new Object[5];
        for (int i=0; i < 5; i++)
            o[i] = new String("A"+i);

        Object[] oo = null;
        try
        {
            oo = (Object[])o.clone();
            if (oo == null)
                throw new Exception("CL9");
        }
        catch (CloneNotSupportedException e)
        {
            throw new Exception("CL10");
        }
        ok = true;
        for (int i=0; i < 5; i++)
            if (!((String)o[i]).equals("A"+i) || !((String)oo[i]).equals("A"+i))
                throw new Exception("CL11");
    }
}
